<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>pytest常用插件 | 移动端测试课程介绍</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-chapter-fold/chapter-fold.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../day3/pytest_prov1.html" />
    
    
    <link rel="prev" href="../day3/pytest_config.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="3.4"
        data-chapter-title="pytest常用插件"
        data-filepath="day3/middle.md"
        data-basepath=".."
        data-revision="Sat Jun 08 2019 07:44:25 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="day1/readme.html">
            
                
                    <a href="../day1/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        移动入门
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="day1/app_test_knowledge.html">
            
                
                    <a href="../day1/app_test_knowledge.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        移动端测试概述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="day1/create_env/readme.html">
            
                
                    <a href="../day1/create_env/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        移动测试环境搭建搭建
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="day1/create_env/java.html">
            
                
                    <a href="../day1/create_env/java.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.1.</b>
                        
                        Java环境搭建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="day1/create_env/sdk.html">
            
                
                    <a href="../day1/create_env/sdk.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.2.</b>
                        
                        Android sdk 环境
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="day1/create_env/geny.html">
            
                
                    <a href="../day1/create_env/geny.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.3.</b>
                        
                        Android 虚拟机安装
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="day1/command_adb.html">
            
                
                    <a href="../day1/command_adb.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        ADB命令
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="day1/app_tools.html">
            
                
                    <a href="../day1/app_tools.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        移动端自动化工具
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="day1/appium_env.html">
            
                
                    <a href="../day1/appium_env.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        appium环境搭建
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="day1/start_appium.html">
            
                
                    <a href="../day1/start_appium.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        appium入门案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="day2/readme.html">
            
                
                    <a href="../day2/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        app操作api
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="day2/base_api.html">
            
                
                    <a href="../day2/base_api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        app基础操作api
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="day2/uiauto.html">
            
                
                    <a href="../day2/uiauto.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        uiautomatorviewer工具
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="day2/location_element.html">
            
                
                    <a href="../day2/location_element.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        app元素定位操作api
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="day2/get_infor.html">
            
                
                    <a href="../day2/get_infor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        根据元素获取信息api
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="day2/element_event.html">
            
                
                    <a href="../day2/element_event.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        元素事件操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="day2/touch_action.html">
            
                
                    <a href="../day2/touch_action.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        模拟手势操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="day2/phone_api.html">
            
                
                    <a href="../day2/phone_api.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        手机操作api
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="day3/readme.html">
            
                
                    <a href="../day3/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        Pytest
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="day3/install_introduction.html">
            
                
                    <a href="../day3/install_introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        pytest安装和介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="day3/setup_teardown.html">
            
                
                    <a href="../day3/setup_teardown.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        setup和teardown函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="day3/pytest_config.html">
            
                
                    <a href="../day3/pytest_config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        pytest的配置文件
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.4" data-path="day3/middle.html">
            
                
                    <a href="../day3/middle.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        pytest常用插件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="day3/pytest_prov1.html">
            
                
                    <a href="../day3/pytest_prov1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        pytest提高1--fixture
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="day3/pytest_prov2.html">
            
                
                    <a href="../day3/pytest_prov2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        pytest提高2
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="day4/readme.html">
            
                
                    <a href="../day4/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        PO模式
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="day4/introduction.html">
            
                
                    <a href="../day4/introduction.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        PO模式介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="day4/project_plan.html">
            
                
                    <a href="../day4/project_plan.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        项目准备
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="day4/logic.html">
            
                
                    <a href="../day4/logic.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        按照业务抽取代码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="day4/find_element.html">
            
                
                    <a href="../day4/find_element.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        抽取的find_element
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="day4/base_action.html">
            
                
                    <a href="../day4/base_action.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        抽取基础动作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="day5/readme.html">
            
                
                    <a href="../day5/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        数据驱动--Yaml
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="day5/introduction_yaml.html">
            
                
                    <a href="../day5/introduction_yaml.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        Yaml介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="day5/pyyaml.html">
            
                
                    <a href="../day5/pyyaml.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        python解析yaml文件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="day5/yaml_data.html">
            
                
                    <a href="../day5/yaml_data.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        yaml数据驱动案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="day6/readme.html">
            
                
                    <a href="../day6/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        Allure报告和Jenkins集成
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="day6/allure.html">
            
                
                    <a href="../day6/allure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        allure介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="day6/pytest_allure.html">
            
                
                    <a href="../day6/pytest_allure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        pytest中使用allure
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="day6/jenkins.html">
            
                
                    <a href="../day6/jenkins.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        Jenkins安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="day6/jenkins_git_allure_email.html">
            
                
                    <a href="../day6/jenkins_git_allure_email.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        Jenkins持续集成配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >移动端测试课程介绍</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5E38;&#x7528;&#x63D2;&#x4EF6;">&#x5E38;&#x7528;&#x63D2;&#x4EF6;</h1>
<h2 id="&#x5B66;&#x4E60;&#x76EE;&#x6807;">&#x5B66;&#x4E60;&#x76EE;&#x6807;</h2>
<ul>
<li>&#x638C;&#x63E1;&#x5E38;&#x7528;&#x7684;&#x63D2;&#x4EF6;</li>
<li>&#x77E5;&#x9053;&#x67E5;&#x627E;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x63D2;&#x4EF6;&#x7684;&#x65B9;&#x6CD5;</li>
</ul>
<h3 id="1-&#x6982;&#x8FF0;">1. &#x6982;&#x8FF0;</h3>
<p>pytest&#x5305;&#x542B;&#x5F88;&#x591A;&#x63D2;&#x4EF6;&#x5305;,&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x9700;&#x6C42;&#x9009;&#x62E9;&#x5B89;&#x88C5;&#x5373;&#x53EF;.</p>
<p><a href="https://plugincompat.herokuapp.com" target="_blank">&#x63D2;&#x4EF6;&#x5217;&#x8868;&#x5730;&#x5740;</a></p>
<p><strong>&#x6211;&#x4EEC;&#x8FD9;&#x91CC;&#x53EA;&#x8BB2;&#x89E3;&#x5E38;&#x7528;&#x7684;!!</strong></p>
<h3 id="2-&#x524D;&#x7F6E;&#x6761;&#x4EF6;">2. &#x524D;&#x7F6E;&#x6761;&#x4EF6;</h3>
<pre><code>1.&#x6587;&#x4EF6;&#x8DEF;&#x5F84;&#xFF1A;
   - Test_App
   - - test_abc.py
   - - pytest.ini
2.pyetst.ini&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#xFF1A;
[pytest]
# &#x547D;&#x4EE4;&#x884C;&#x53C2;&#x6570;
addopts = -s
# &#x641C;&#x7D22;&#x6587;&#x4EF6;&#x540D;
python_files = test_*.py
# &#x641C;&#x7D22;&#x7684;&#x7C7B;&#x540D;
python_classes = Test_*
# &#x641C;&#x7D22;&#x7684;&#x51FD;&#x6570;&#x540D;
python_functions = test_*
</code></pre><h3 id="3&#x5E38;&#x7528;&#x63D2;&#x4EF6;">3.&#x5E38;&#x7528;&#x63D2;&#x4EF6;</h3>
<h4 id="31--pytest&#x6D4B;&#x8BD5;&#x62A5;&#x544A;">3.1  pytest&#x6D4B;&#x8BD5;&#x62A5;&#x544A;</h4>
<p><strong>&#x4F5C;&#x7528;</strong>: &#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x884C;&#x65B9;&#x5F0F;&#xFF0C;&#x751F;&#x6210;xml/html&#x683C;&#x5F0F;&#x7684;&#x6D4B;&#x8BD5;&#x62A5;&#x544A;&#xFF0C;&#x5B58;&#x50A8;&#x4E8E;&#x7528;&#x6237;&#x6307;&#x5B9A;&#x8DEF;&#x5F84;&#x3002;</p>
<p><strong>&#x5B89;&#x88C5;&#x65B9;&#x5F0F;: </strong> pip install pytest-html</p>
<p><strong>&#x4F7F;&#x7528;&#x65B9;&#x6CD5;:</strong> </p>
<p>&#x200B;    &#x547D;&#x4EE4;&#x884C;&#x683C;&#x5F0F;: pytest &#x2014;html=&#x5B58;&#x50A8;&#x8DEF;&#x5F84;/report.html</p>
<p><strong>&#x793A;&#x4F8B;&#x4EE3;&#x7801;1 </strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pytest

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test_ABC</span>:</span>
        <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">setup_class</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;-----&gt; setup_class&quot;</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">teardown_class</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;----&gt; teardown_class&quot;</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_a</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;----&gt; test_a&quot;</span>)
        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_b</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;----&gt; test_b&quot;</span>)
        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span>
</code></pre>
<p><strong>&#x540C;&#x65F6;&#x66F4;&#x6539;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</strong></p>
<ul>
<li><p>&#x4FEE;&#x6539;Test_App/pytest.ini&#x6587;&#x4EF6;&#xFF0C;&#x6DFB;&#x52A0;&#x62A5;&#x544A;&#x53C2;&#x6570;&#xFF0C;&#x5373;&#xFF1A;addopts = -s --html=./report.html </p>
<p>&#x53C2;&#x6570;&#x89E3;&#x91CA;:</p>
<ul>
<li>-s&#x662F;&#x8F93;&#x51FA;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x4FE1;&#x606F;</li>
<li>&#x2014;html=./report.ml &#x5728;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x751F;&#x6210;report.html&#x6587;&#x4EF6;</li>
</ul>
<p>&#x26A0;&#xFE0F; &#x82E5;&#x8981;&#x751F;&#x6210;xml&#x6587;&#x4EF6;&#xFF0C;&#x53EF;&#x5C06;--html=./report.html &#x6539;&#x6210; --html=./report.xml</p>
</li>
</ul>
<h4 id="32-pytest-&#x63A7;&#x5236;&#x51FD;&#x6570;&#x6267;&#x884C;&#x987A;&#x5E8F;">3.2 Pytest &#x63A7;&#x5236;&#x51FD;&#x6570;&#x6267;&#x884C;&#x987A;&#x5E8F;</h4>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;pytest&#x662F;&#x6839;&#x636E;&#x6D4B;&#x8BD5;&#x65B9;&#x6CD5;&#x540D;&#x7531;&#x5C0F;&#x5230;&#x5927;&#x6267;&#x884C;&#x7684;,&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7B2C;&#x4E09;&#x65B9;&#x63D2;&#x4EF6;&#x5305;&#x6539;&#x53D8;&#x5176;&#x8FD0;&#x884C;&#x987A;&#x5E8F;&#x3002;</p>
<p><strong>&#x4F5C;&#x7528;:</strong> &#x4EE5;&#x51FD;&#x6570;&#x4FEE;&#x9970;&#x7B26;&#x7684;&#x65B9;&#x5F0F;&#x6807;&#x8BB0;&#x88AB;&#x6D4B;&#x51FD;&#x6570;,&#x901A;&#x8FC7;&#x53C2;&#x6570;&#x63A7;&#x5236;&#x51FD;&#x6570;&#x6267;&#x884C;&#x987A;&#x5E8F;</p>
<p><strong>&#x5B89;&#x88C5;&#x63D2;&#x4EF6;:</strong> pip install pytest-ordering</p>
<p><strong>&#x4F7F;&#x7528;&#x65B9;&#x6CD5;:</strong></p>
<ol>
<li>&#x6807;&#x8BB0;&#x4E8E;&#x88AB;&#x6D4B;&#x51FD;&#x6570;, @pytest.mark.run(order=x)</li>
<li><p>&#x6839;&#x636E;order&#x4F20;&#x5165;&#x53C2;&#x6570;&#x6765;&#x51B3;&#x5B9A;&#x8FD0;&#x884C;&#x987A;&#x5E8F;:</p>
<ol>
<li>order&#x503C;&#x5168;&#x4E3A;&#x6B63;&#x6570;&#x6216;&#x5168;&#x4E3A;&#x8D1F;&#x6570;&#x65F6;, &#x503C;&#x8D8A;&#x5C0F;,&#x4F18;&#x5148;&#x7EA7;&#x8D8A;&#x9AD8;</li>
<li>&#x6B63;&#x6570;&#x548C;&#x8D1F;&#x6570;&#x540C;&#x65F6;&#x5B58;&#x5728;,&#x6B63;&#x6570;&#x4F18;&#x5148;&#x7EA7;&#x9AD8;</li>
</ol>
<p>&#x603B;&#x7ED3;&#xFF1A; 0 &gt; &#x8F83;&#x5C0F;&#x6574;&#x6570;&gt; &#x8F83;&#x5927;&#x7684;&#x6574;&#x6570; &gt; &#x65E0;&#x6807;&#x8BB0; &gt; &#x8F83;&#x5C0F;&#x7684;&#x8D1F;&#x6570; &gt; &#x8F83;&#x5927;&#x7684;&#x8D1F;&#x6570; </p>
</li>
</ol>
<p><strong>&#x793A;&#x4F8B;&#x4EE3;&#x7801;2</strong></p>
<pre><code class="lang-python">import pytest


class Test_ABD:
        def setup_class(self):
          print(&quot;-----&gt; setup_class&quot;)

    def teardown_class(self):
          print(&quot;----&gt; teardown_class&quot;)

    @pytest.mark.run(order=2)
    def test_a(self):
          print(&quot;----&gt; test_a&quot;)
        assert 1

    @pytest.mark.run(order=1)
    def test_b(self):
          print(&quot;----&gt; test_b&quot;)
        assert 0

if __name__ == &quot;__main__&quot;:
      pytest.main(&quot;-s test_abc.py&quot;)

&#x6267;&#x884C;&#x7ED3;&#x679C;&#xFF1A;
        test_abc.py
        -------&gt;setup_class
        -------&gt;test_b # order=1 &#x4F18;&#x5148;&#x8FD0;&#x884C;
        F
        -------&gt;test_a # order=2 &#x665A;&#x4E8E; order=1 &#x8FD0;&#x884C;
        .
        -------&gt;teardown_class
</code></pre>
<h3 id="33-&#x5931;&#x8D25;&#x91CD;&#x8BD5;">3.3 &#x5931;&#x8D25;&#x91CD;&#x8BD5;</h3>
<p><strong>&#x63D2;&#x4EF6;&#x540D;&#x79F0;:</strong> pytest-rerunfailures</p>
<p><strong>&#x4F5C;&#x7528;:</strong> &#x4F7F;&#x7528;&#x547D;&#x4EE4;&#x884C;&#x65B9;&#x5F0F;,&#x63A7;&#x5236;&#x5931;&#x8D25;&#x51FD;&#x6570;&#x7684;&#x91CD;&#x8BD5;&#x6B21;&#x6570;.</p>
<p><strong>&#x5B89;&#x88C5;&#x65B9;&#x5F0F;:</strong> pip install pytest-rerunfailures</p>
<p><strong>&#x4F7F;&#x7528;&#x65B9;&#x6CD5;:</strong></p>
<p>&#x200B;        &#x547D;&#x4EE4;&#x884C;&#x683C;&#x5F0F;, pytest &#x2014;rerun  n # n&#x4E3A;&#x91CD;&#x8BD5;&#x7684;&#x6B21;&#x6570;</p>
<p><strong>&#x793A;&#x4F8B;&#x4EE3;&#x7801;3</strong></p>
<pre><code class="lang-py"><span class="hljs-keyword">import</span> pytest


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Test_ABD</span>:</span>
        <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">setup_class</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;-----&gt; setup_class&quot;</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">teardown_class</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;----&gt; teardown_class&quot;</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_a</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;----&gt; test_a&quot;</span>)
        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_b</span><span class="hljs-params">(self)</span>:</span>
          print(<span class="hljs-string">&quot;----&gt; test_b&quot;</span>)
        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span>

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&quot;__main__&quot;</span>:
      pytest.main(<span class="hljs-string">&quot;-s test_abc.py&quot;</span>)
</code></pre>
<p><strong>&#x4FEE;&#x6539;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</strong> , &#x4FEE;&#x6539;Test_App/pytest.ini&#x6587;&#x4EF6;&#xFF0C;&#x6DFB;&#x52A0;&#x5931;&#x8D25;&#x91CD;&#x8BD5;&#x53C2;&#x6570;&#xFF0C;&#x5373;&#xFF1A;addopts = -s  --reruns 2 --html=./report.html </p>
<p>&#x53C2;&#x6570;&#x89E3;&#x91CA;:</p>
<ul>
<li>-s&#x662F;&#x8F93;&#x51FA;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x4FE1;&#x606F;</li>
<li>&#x2014;rerun 2 : &#x5931;&#x8D25;&#x91CD;&#x8BD5;2&#x6B21;</li>
<li>&#x2014;html=./report.ml &#x5728;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x751F;&#x6210;report.html&#x6587;&#x4EF6;</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../day3/pytest_config.html" class="navigation navigation-prev " aria-label="Previous page: pytest的配置文件"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../day3/pytest_prov1.html" class="navigation navigation-next " aria-label="Next page: pytest提高1--fixture"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"expandable-chapters-small":{},"splitter":{},"chapter-fold":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
